<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>map的遍历方法</h2>
    <ul>
        <li>keys()：</li>
        <li>values()：</li>
        <li>entries()：</li>
    </ul>
    <script>
        let map = new Map([["name","奉先"],["age",35]]);

        console.log("-----------遍历keys()----------------")
        for (let key of map.keys()) {
            console.log(key,"=",map.get(key));
        }

        console.log("-----------遍历values()----------------")
        for (let value of map.values()) {
            console.log(value);
        }

        console.log("-----------遍历entries()----------------")
        for (let entry of map.entries()) {
            console.log(entry[0]," = ",entry[1]);
        }


        console.log("-----------遍历forEach()----------------")
        // 参数一：map的value
        // 参数二：map的key
        // 参数三：map本身的引用
        map.forEach((v,k,m) => {
            console.log(k," = ",v);
            console.log(m);
        })

        // map的遍历函数，实际上就是entries()
        console.log(map[Symbol.iterator] === map.entries); // true
        console.log(Map.prototype[Symbol.iterator] === map.entries); // true
        console.log(map.entries() === map.entries());

    </script>
</body>
</html>